package com.itheima.test8;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;

/**
 * @Author:gy
 * @Date: 2025/09/04 11:39
 * @Description:
 */
public class ServerDemo {
    public static void main(String[] args) throws Exception {
          //先接受的客户端传过来的数据
        ServerSocket ss = new ServerSocket(10010);
        while (true) {
            //监听客户端的信息
            Socket socket = ss.accept();
            //获取里面的信息  网络中流读
            BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
            //读完图片后  写到本地  本地的输出流
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("Day14\\"+System.currentTimeMillis()+".png"));
            //BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("Day14\\"+ UUID.randomUUID().toString().replace("-","")+".png"));
            int b;
            while ((b = bis.read()) != -1) {
                bos.write(b);
            }
            bos.flush();
            //写到本地之后  给出反馈  网络的输出流
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
            bw.write("上传成功");
            bw.newLine();
            ;
            //关闭资源
            bw.close();
            bos.close();
            socket.close();
        }
        //ss.close();
    }
}
